<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Profil extends CI_Controller {

	function __construct() {
    parent::__construct();
    $this->isLogin();	
		$this->load->model("master/master_profil"); 
	}
	
	function isLogin(){
		$login=$this->session->userdata('isLogin');
		if(! isset($login)||$login != true){
			$this->session->set_flashdata('error_login', 'Untuk Mengakses Admin Anda Harus Login!');
			redirect('login');	
		}
	}

	function index()
	{		
		$data['main_view']='master/mr_profil/read';
		$this->load->view('index',$data);
		
	}

	function update()
	{
		$this->load->library('form_validation');
		$this->form_validation->set_rules('nama', 'Nama Lengkap Pengguna', 'required');

		if ($this->form_validation->run()==FALSE){
            $data['main_view']='master/mr_profil/read';
			$this->load->view('index',$data);
        }else {

			$id_user	=	$this->input->post('id_user');		
			$password	=	$this->input->post('password');		
			$dataUpdate1	=	array(
				'nama' 		=> $this->input->post('nama')
			);
			$dataUpdate2	=	array(
				'nama' 		=> $this->input->post('nama'),
				'password' 	=> md5($password)
			);
			if(empty($password)){
				$dataUpdate = $dataUpdate1;
			}else{
				$dataUpdate = $dataUpdate2;
			}
			$this->master_profil->update($id_user,$dataUpdate);
			redirect('login/logout');
		}
	}

}